var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/query-panel/service.ts
var service_exports = {};
__export(service_exports, {
  addQueryScheme: () => addQueryScheme,
  deleteQueryScheme: () => deleteQueryScheme,
  getQueryPanelInfo: () => getQueryPanelInfo,
  getQueryScheme: () => getQueryScheme,
  getQuerySchemeData: () => getQuerySchemeData,
  getQuerySchemeDetail: () => getQuerySchemeDetail,
  getQuerySchemeTree: () => getQuerySchemeTree,
  getQuerySettingInfo: () => getQuerySettingInfo,
  resetQuerySettingInfo: () => resetQuerySettingInfo,
  saveQuerySchemeData: () => saveQuerySchemeData,
  saveQuerySettingInfo: () => saveQuerySettingInfo,
  setQueryPanelData: () => setQueryPanelData,
  updateQuerySchemeStatus: () => updateQuerySchemeStatus
});
module.exports = __toCommonJS(service_exports);
var import_util = require("../../util");
async function getQueryPanelInfo({ pageId }) {
  if ((0, import_util.hasServiceAdapter)("queryPanel", "getQueryPanelInfo")) {
    return await (0, import_util.execServiceAdapter)("queryPanel", "getQueryPanelInfo", { pageId });
  }
  const { code, data } = await import_util.iup.request.get({
    url: `engine/metadata/queryPanel/getQueryPanelUIControl`,
    data: { pageId }
  });
  if (code === 0) {
    const fields = data.list || [];
    const values = data.rememberStr || {};
    fields.reduce((p, c) => {
      if (values[c.name] && values[`[${c.name}]`]) {
        values[c.name] = values[`[${c.name}]`];
        return p;
      }
      return p;
    }, []);
    return {
      fields,
      values,
      isChecked: data.isCheck === "1"
    };
  }
  return { fields: [], values: {}, isChecked: false };
}
async function setQueryPanelData({ pageId, values, checked }) {
  if (!values) {
    return true;
  }
  const rememberStr = checked ? values : {};
  const rememberString = import_util.iup.jsonString(
    Object.keys(rememberStr).reduce((p, key) => {
      const keyValue = values[key];
      if (import_util.iup.isNullOrEmpty(keyValue) || keyValue.length === 0) {
        return p;
      } else {
        if (keyValue.hasOwnProperty("value")) {
          return {
            ...p,
            [`[${key}]`]: { value: keyValue.value, label: keyValue.label },
            [key]: keyValue.value
          };
        }
        if (import_util.iup.isArray(keyValue) && keyValue[0].hasOwnProperty("value")) {
          return {
            ...p,
            [`[${key}]`]: keyValue.map((v) => ({ value: v.value, label: v.label })),
            [key]: keyValue.map((v) => v.value).join()
          };
        }
        return {
          ...p,
          [key]: keyValue
        };
      }
    }, {})
  );
  if ((0, import_util.hasServiceAdapter)("queryPanel", "setQueryPanelData")) {
    return await (0, import_util.execServiceAdapter)("queryPanel", "setQueryPanelData", {
      pageId,
      rememberString,
      isCheck: checked ? 1 : 0
    });
  }
  const { code } = await import_util.iup.request.post({
    url: `engine/metadata/queryPanel/setQueryPanelData`,
    data: {
      pageId,
      rememberString,
      isCheck: checked ? 1 : 0
    }
  });
  return code === 0;
}
async function getQuerySettingInfo({ pageId }) {
  if ((0, import_util.hasServiceAdapter)("queryPanel", "getQuerySettingInfo")) {
    return await (0, import_util.execServiceAdapter)("queryPanel", "getQuerySettingInfo", { pageId });
  }
  const { code, data } = await import_util.iup.request.get({
    url: `engine/metadata/queryPanel/getQueryPanelInfo?pageId=${pageId}`
  });
  return code === 0 ? data : [];
}
async function saveQuerySettingInfo({ pageId, data }) {
  if ((0, import_util.hasServiceAdapter)("queryPanel", "getQuerySettingInfo")) {
    return await (0, import_util.execServiceAdapter)("queryPanel", "saveQuerySettingInfo", { pageId, data });
  }
  const { code, message: msg } = await import_util.iup.request.post({
    url: `engine/metadata/queryPanel/saveQueryInfo?pageId=${pageId}`,
    data: {
      queryPanelRequests: import_util.iup.CryptoJS.encode(data)
    }
  });
  if (code === 0) {
    return true;
  }
  msg && import_util.iup.message(msg, "error");
  return false;
}
function resetQuerySettingInfo({ pageId }) {
  if ((0, import_util.hasServiceAdapter)("queryPanel", "resetQuerySettingInfo")) {
    return (0, import_util.execServiceAdapter)("queryPanel", "resetQuerySettingInfo", { pageId });
  }
  return import_util.iup.request.post({
    url: `engine/metadata/queryPanel/restoreDefault?pageId=${pageId}`
  });
}
async function getQueryScheme({ pageId }) {
  return [];
}
async function getQuerySchemeDetail({ schemeId }) {
  return await import_util.iup.request.get({
    url: `MDP/BusObj/QuerySetting/DealSchemeFields`,
    data: {
      schemeid: schemeId
    }
  });
}
async function getQuerySchemeTree({ pageId }) {
  const { data = [] } = await import_util.iup.request.get({
    url: `MDP/BusObj/QuerySetting/GetSchemeTreeByPageId`,
    data: {
      pageid: pageId,
      node: "root"
    }
  });
  return data.map((r, index) => ({ key: r.id, title: r.text, isLeaf: true, isSelected: index === 0 }));
}
async function getQuerySchemeData({ schemeId }) {
  if (!schemeId) {
    return [];
  }
  const result = await import_util.iup.request.get({
    url: `MDP/BusObj/QuerySetting/GetSchemeFieldList`,
    data: {
      schemeid: schemeId,
      page: 0,
      start: 0,
      limit: 50
    }
  });
  return result.data || [];
}
async function addQueryScheme({ schemeName, pageId }) {
  const { code } = await import_util.iup.request.post({
    url: `MDP/BusObj/QuerySetting/SaveScheme`,
    data: { cname: schemeName, pageid: pageId, isperson: 1 }
  });
  return code === 0;
}
async function deleteQueryScheme({ schemeId }) {
  const { code } = await import_util.iup.request.get({
    url: `MDP/BusObj/QuerySetting/DeleteScheme`,
    data: {
      schemeid: schemeId
    }
  });
  return code === 0;
}
async function updateQuerySchemeStatus({ schemeId, status }) {
  const { code } = await import_util.iup.request.get({
    url: `MDP/BusObj/QuerySetting/OpenOrCloseScheme`,
    data: {
      schemeid: schemeId,
      status
    }
  });
  return code === 0;
}
async function saveQuerySchemeData({ schemeId, data }) {
  const { code, message: msg } = await import_util.iup.request.post({
    url: `MDP/BusObj/QuerySetting/SaveSchemeDetail`,
    data: {
      schemeid: schemeId,
      data: import_util.iup.CryptoJS.encode(data)
    }
  });
  return code === 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  addQueryScheme,
  deleteQueryScheme,
  getQueryPanelInfo,
  getQueryScheme,
  getQuerySchemeData,
  getQuerySchemeDetail,
  getQuerySchemeTree,
  getQuerySettingInfo,
  resetQuerySettingInfo,
  saveQuerySchemeData,
  saveQuerySettingInfo,
  setQueryPanelData,
  updateQuerySchemeStatus
});
